package com.bff.gaia.streaming.api.mo.gaia.network.client;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.SocketException;
import java.net.UnknownHostException;

public abstract class AClient {

	private String cmd;
	private String host;
	private int port;
	String key;

	public AClient(String host, int port, String key, String cmd) {
		this.host = host;
		this.port = port;
		this.key = key;
		this.cmd = cmd;
	}
	public AClient(String host, int port, String key) {
		this.host = host;
		this.port = port;
		this.key = key;
	}


	public void connect() {
		try {
			Socket a = new Socket(this.host, this.port);
			BufferedOutputStream out = new BufferedOutputStream(a.getOutputStream());
			BufferedInputStream in = new BufferedInputStream(a.getInputStream());
			this.dojob(in,out);
			a.close();
		} catch (IOException var9) {
			var9.printStackTrace();
		}
	}

	protected abstract void dojob(BufferedInputStream in, BufferedOutputStream out) throws IOException;

	public void connectArray() {
		try {
			Socket a = new Socket(this.host, this.port);
			BufferedOutputStream out = new BufferedOutputStream(a.getOutputStream());
			BufferedInputStream in = new BufferedInputStream(a.getInputStream());
			this.dojobArray(in,out);
			a.close();
		} catch (UnknownHostException var9) {
			var9.printStackTrace();
		} catch (SocketException var10) {
		} catch (IOException var11) {
			var11.printStackTrace();
		}

	}

	protected abstract void dojobArray(BufferedInputStream in, BufferedOutputStream out) throws IOException;

	public String getCmd() {
		return this.cmd;
	}

	public void setCmd(String cmd) {
		this.cmd = cmd;
	}

	public String getKey() {
		return this.key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public String getHost() {
		return this.host;
	}

	public void setHost(String host) {
		this.host = host;
	}

	public int getPort() {
		return this.port;
	}

	public void setPort(int port) {
		this.port = port;
	}
}